﻿using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;

namespace SugarDemo
{
    //public class MyConditionalModel : ConditionalModel{
    //    public MyConditionalModel(ConditionalCollections collection) {
    //        this.ConditionalType = collection.w
    //    }
    //}
    class Program
    {
        static void Main(string[] args)
        {
            List<IConditionalModel> conModels = new List<IConditionalModel>();
            conModels.Add(new ConditionalModel() { FieldName = "Name", ConditionalType = ConditionalType.Like, FieldValue = "杨" });
            conModels.Add(new ConditionalModel() { FieldName = "Age", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = "20" });
            conModels.Add(new ConditionalModel() { FieldName = "OrganizeID", ConditionalType = ConditionalType.Equal, FieldValue = "23" });
            conModels.Add(new ConditionalCollections()
            {
                ConditionalList =
                    new List<KeyValuePair<WhereType, ConditionalModel>>()
                    {
                        new  KeyValuePair<WhereType, ConditionalModel>
                        ( WhereType.And ,
                        new ConditionalModel() { FieldName = "PostID", ConditionalType = ConditionalType.In, FieldValue = "[1,2,3,4,5]" }),
                        new  KeyValuePair<WhereType, ConditionalModel>
                        (WhereType.Or,
                        new ConditionalModel() { FieldName = "TypeID", ConditionalType = ConditionalType.Equal, FieldValue = "164716494974" }),
                        new  KeyValuePair<WhereType, ConditionalModel>
                        ( WhereType.And,
                        new ConditionalModel() { FieldName = "EducateStartDate", ConditionalType = ConditionalType.GreaterThan, FieldValue = "1995-10-20" }),


                        new  KeyValuePair<WhereType, ConditionalModel>(
                               //WhereType.And,
                               //new ConditionalCollections(){
                               //    ConditionalList = null
                               //}
                        )

                    }
            });


            Console.WriteLine(JsonConvert.SerializeObject(conModels));

            var searchCondition = "[{'ConditionalList':[{'Key':0,'Value':{'FieldName':'Name','FieldValue':'杨','ConditionalType':1,'FieldValueConvertFunc':null}},{'Key':0,'Value':{'FieldName':'Age','FieldValue':'20','ConditionalType':3,'FieldValueConvertFunc':null}},{'Key':0,'Value':{'FieldName':'OrganizeID','FieldValue':'23','ConditionalType':0,'FieldValueConvertFunc':null}},{'Key':0,'Value':{'FieldName':'PostID','FieldValue':'[1,2,3,4,5]','ConditionalType':6,'FieldValueConvertFunc':null}},{'Key':1,'Value':{'FieldName':'TypeID','FieldValue':'164716494974','ConditionalType':0,'FieldValueConvertFunc':null}},{'Key':0,'Value':{'FieldName':'EducateStartDate','FieldValue':'1995-10-20','ConditionalType':2,'FieldValueConvertFunc':null}}]}]";
            //conModels = new List<IConditionalModel>();
            var temp = JsonConvert.DeserializeObject<List<ConditionalModel>>(searchCondition);
            
            Console.ReadLine();
        }
    }
}
